package cn.appsys.controller;

import java.io.FileOutputStream;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.validation.ObjectError;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;

import cn.appsys.biz.CategoryBiz;
import cn.appsys.biz.DictionaryBiz;
import cn.appsys.biz.InfoBiz;
import cn.appsys.entity.AppCategory;
import cn.appsys.entity.AppInfo;
import cn.appsys.entity.DataDictionary;
import cn.appsys.entity.DevUser;


@Controller
public class InsertAppController {
	
	@Autowired
	private InfoBiz infoBiz;
	@Autowired
	private CategoryBiz categoryBiz;
	@Autowired
	private DictionaryBiz dictionaryBiz;
	@RequestMapping("/addandupdate")
	public String addandupdate(Model model){
		List<DataDictionary> flatformList=dictionaryBiz.getByFlatform();
		List<AppCategory> listone =categoryBiz.getAllCategory();
		
		model.addAttribute("listone",listone);
		model.addAttribute("flatformList", flatformList);
		return "addandupdate";
	}
	@RequestMapping(value="/doaddandupdate",  method = RequestMethod.POST)
	public void doaddandupdate(AppInfo appInfo,HttpSession session){
		
		DevUser devUser=(DevUser)session.getAttribute("developer");
		System.out.println(devUser);
		appInfo.setDevId(devUser.getId());
		appInfo.setLogoLocPath(appInfo.getLogoPicPath());
		int temp=infoBiz.insertApp(appInfo);
		System.out.println(temp);
	}
	
}
